package com.quartz.springbootquartz.simple;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class JobDemo {


    public static void main(String[] args) throws SchedulerException {
        /*
        3个对象
        调度器：scheduler
        任务：Job&JobDetail
        触发器：Trigger
        关系是：一个任务可以被多个触发器触发
               一个触发器执行触发一个任务
         */

        /*
        编写流程：
        1.任务
        2.触发器
        3.调度器
         */

        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJob", "myGroup")
                .usingJobData("name", "zhxl")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                // 触发器标识
                .withIdentity("trigger1", "trigger1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(2).repeatForever())
                .startNow()
                .build();

        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();

    }
}